using UnityEngine;
using System.Collections;

public class Darkness : MonoBehaviour {
	
	public Transform target;
	public float intensity;
	
	public void Start () {
		float color = intensity/256;
		RenderSettings.ambientLight = new Color(color,color,color,0);
	}
	
	void Update () {
		if (target) {
		    float color = Vector3.Distance(target.position, transform.position);
			if(color > intensity){
				color = intensity/256;
			}
			else if (color > 20){
				color = (color-10)/256;
			}
			else {
				color = (color-(color/2))/256;
			}
			
		    RenderSettings.ambientLight = new Color(color,color,color,0);
		}
	}
}
